package com.humanminoritygame;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.humanminoritygame.common.Utils;
import com.humanminoritygame.model.Category;
import com.humanminoritygame.model.HibernateCategoryRepo;
import com.humanminoritygame.model.HibernateQuestionRepo;
import com.humanminoritygame.model.HibernateUserRepo;
import com.humanminoritygame.model.Question;
import com.humanminoritygame.model.User;
import com.humanminoritygame.model.UserType;


public class CreateSamples {

  
  public static void main(String[] args) {
    System.out.println("RECORDAR VACIAR LAS TABLAS ANTES DE CORRER ESTO!");
    BasicConfigurator.configure();
    Logger.getRootLogger().setLevel(Level.INFO);
    ApplicationContext ctx = new FileSystemXmlApplicationContext("src/main/webapp/WEB-INF/dispatcher-servlet.xml");
    
    HibernateCategoryRepo categoryRepo = (HibernateCategoryRepo) ctx.getBean("categoryRepo");
    HibernateQuestionRepo questionRepo = (HibernateQuestionRepo) ctx.getBean("questionRepo");
    HibernateUserRepo userRepo = (HibernateUserRepo) ctx.getBean("userRepo");
    SessionFactory sessionFactory = (SessionFactory) ctx.getBean("sessionFactory");
    
    sessionFactory.getCurrentSession().beginTransaction();
    
    categoryRepo.addCategory(new Category("once a day", 24*60*60));
//    categoryRepo.addCategory(new Category("once every two seconds", 2));
//    categoryRepo.addCategory(new Category("once every five seconds", 5));
//    categoryRepo.addCategory(new Category("once a week", 7*24*60*60));
//    categoryRepo.addCategory(new Category("once a minute", 60));
//    categoryRepo.addCategory(new Category("once an hour", 3600));
    categoryRepo.addCategory(new Category("once every 10 seconds", 10));
//    categoryRepo.addCategory(new Category("once every 11 seconds", 11));
//    categoryRepo.addCategory(new Category("once every 12 seconds", 12));
//    categoryRepo.addCategory(new Category("once every 13 seconds", 13));
//    categoryRepo.addCategory(new Category("once every 14 seconds", 14));
//    categoryRepo.addCategory(new Category("once every 15 seconds", 15));
//    categoryRepo.addCategory(new Category("once every 16 seconds", 16));
//    categoryRepo.addCategory(new Category("once every 17 seconds", 17));
//    categoryRepo.addCategory(new Category("once every 18 seconds", 18));
//    categoryRepo.addCategory(new Category("once every 19 seconds", 19));
    categoryRepo.addCategory(new Category("once every 20 seconds", 20));
//    categoryRepo.addCategory(new Category("once every 21 seconds", 21));
//    categoryRepo.addCategory(new Category("once every 30 seconds", 30));
//    categoryRepo.addCategory(new Category("once every 2 days", 2*24*60*60));
//    categoryRepo.addCategory(new Category("once every 5 minutes", 5*60));
    
    Question q1 = new Question("Heads or Tails?", "Heads", "Tails");
    Question q2 = new Question("Take the Highway or the Old Road?", "Highway", "Old Road");
    Question q3 = new Question("Up or Down?", "Up", "Down");
    Question q4 = new Question("Buy or Sell?", "Buy", "Sell");
    questionRepo.addQuestion(q1);
    questionRepo.addQuestion(q2);
    questionRepo.addQuestion(q3);
    questionRepo.addQuestion(q4);
    
    User user1 = new User("cachi", Utils.encrypt("prueba123"), "cachi77@gmail.com");
    User user2 = new User("lucila", Utils.encrypt("prueba123"), "lucilastancato@gmail.com");
    User user3 = new User("daniel", Utils.encrypt("prueba123"), "dparisi@itba.edu.ar");
    User user4 = new User("researcher", Utils.encrypt("prueba123"), "lupueblerina@hotmail.ar");
    user1.setType(UserType.ADMIN);
    user2.setType(UserType.ADMIN);
    user3.setType(UserType.ADMIN);
    user4.setType(UserType.RESEARCHER);
    userRepo.addUser(user1);
    userRepo.addUser(user2);
    userRepo.addUser(user3);
    userRepo.addUser(user4);
    userRepo.addUser(new User("baseUser", "prueba123", "lupueblerina@hotmail.ar"));

    User r1 = new User("winner", "_", "a@h.com");
    r1.setRobot();
    userRepo.addUser(r1);
    User r2 = new User("buh", "_", "a@h.com");
    r2.setRobot();
    userRepo.addUser(r2);
    User r3 = new User("sole", "_", "a@h.com");
    r3.setRobot();
    userRepo.addUser(r3);

    sessionFactory.getCurrentSession().getTransaction().commit();
  }

  
  
}
